/*
 * 创建日期 2010-1-4
 *
 * 成都天和软件公司
 * 电话：028-85425861
 * 传真：028-85425861-8008
 * 邮编：610041 
 * 版权所有
 */
package  org.fantasy.common.grid.export;

import  org.fantasy.common.grid.bean.ReportParam;
import  org.fantasy.common.grid.report.ReportBuilder;
import  org.fantasy.common.grid.report.ReportBuilderFactory;
import  org.fantasy.common.util.Request;
import  org.fantasy.common.util.RequestUtil;

import java.io.OutputStreamWriter;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *  导出Html
 * @author: 王文成
 * @version: 1.0
 * @since 2010-1-4
 */
public class ExportHtml extends BaseExport{
    
    /**
    * 导出Html
    * @param servletRequest
    * @param response
    * @throws Exception
     */
    @Override
    public void export(HttpServletRequest servletRequest, HttpServletResponse response) throws Exception {
        Request request = RequestUtil.getWrapRequest(servletRequest);
        ReportParam param = getExportParam(request);
        ReportBuilder builder = ReportBuilderFactory.getReportExcelBuilder(param);
        String encodeFileName = getFileName(request,param);
        if (!response.isCommitted())
            response.reset();
        response.setHeader("Pragma", "");
        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("Content-Type", "application/vnd.ms-excel");
        response.setHeader("Content-Disposition", "attachment; filename=" + encodeFileName);
        ServletOutputStream out = response.getOutputStream();
        OutputStreamWriter writer = new OutputStreamWriter(out, "GBK");
        writer.write("<meta http-equiv=Content-Type content=\"text/html; charset=GBK\">");
        writer.write("<style>td{mso-style-parent:style0;mso-number-format:'\\@';white-space:normal;font-size:x-small;}</style>");
        writer.write(builder.getReport().toString());
        writer.flush();
        writer.close();
    }
}
